package com.ldcc.report_system.adapter;

import android.view.View;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.ldcc.report_system.R;

/**
 * @author wwj[yeshengkele@outlook.com]
 * @description 加载状态viewHolder
 */
public class FooterHolder extends RecyclerView.ViewHolder {

    /**
     * 状态不可见
     */
    public final static int NORMAL = 0;
    /**
     * 正在加载状态
     */
    public final static int LOADING = 1;
    /**
     * 结束状态
     */
    public final static int THE_END = 2;
    /**
     * 网络错误
     */
    public final static int NET_WORK_ERROR = 3;


    // 正在加载
    private LinearLayout loadingView;
    // 加载结束
    private LinearLayout endView;
    // 网络错误
    private LinearLayout networkError;


    public FooterHolder(@NonNull View itemView) {
        super(itemView);
        this.loadingView = itemView.findViewById(R.id.loading_view);
        this.endView = itemView.findViewById(R.id.end_view);
        this.networkError = itemView.findViewById(R.id.network_error);
    }

    /**
     * @param status 状态码
     * @description 设置状态
     */
    public void setStatus(int status) {
        setAllGone();
        switch (status) {
            case FooterHolder.LOADING:
                this.loadingView.setVisibility(View.VISIBLE);
                break;
            case FooterHolder.THE_END:
                this.endView.setVisibility(View.VISIBLE);
                break;
            case FooterHolder.NET_WORK_ERROR:
                this.networkError.setVisibility(View.VISIBLE);
                break;
        }
    }

    /***
     * @description 全部不可见
     */
    public void setAllGone() {
        if (this.loadingView != null) {
            this.loadingView.setVisibility(View.GONE);
        }
        if (this.endView != null) {
            this.endView.setVisibility(View.GONE);
        }
        if (this.networkError != null) {
            this.networkError.setVisibility(View.GONE);
        }

    }

}
